package com.google.android.gms.internal;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.RemoteException;
import android.text.TextUtils;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.gms.ads.internal.zzbb;
import com.google.android.gms.common.internal.Hide;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

@Hide
@zzabh
public final class zzzy implements Callable<zzahd> {
    private static long zzcow = 10;
    private final Context mContext;
    private int mErrorCode;
    private final Object mLock = new Object();
    private final zzov zzanh;
    private final zzaan zzarm;
    private final zzcv zzbyz;
    private final zzahe zzcob;
    private final zzajr zzcox;
    /* access modifiers changed from: private */
    public final zzbb zzcoy;
    private boolean zzcoz;
    private List<String> zzcpa;
    private JSONObject zzcpb;
    private String zzcpc;

    public zzzy(Context context, zzbb zzbb, zzajr zzajr, zzcv zzcv, zzahe zzahe, zzov zzov) {
        this.mContext = context;
        this.zzcoy = zzbb;
        this.zzcox = zzajr;
        this.zzcob = zzahe;
        this.zzbyz = zzcv;
        this.zzanh = zzov;
        this.zzarm = zzbb.zzds();
        this.zzcoz = false;
        this.mErrorCode = -2;
        this.zzcpa = null;
        this.zzcpc = null;
    }

    private final zzalt<zzpj> zza(JSONObject jSONObject, boolean z, boolean z2) throws JSONException {
        String string = z ? jSONObject.getString("url") : jSONObject.optString("url");
        double optDouble = jSONObject.optDouble("scale", 1.0d);
        boolean optBoolean = jSONObject.optBoolean("is_transparent", true);
        if (!TextUtils.isEmpty(string)) {
            return z2 ? zzali.zzh(new zzpj((Drawable) null, Uri.parse(string), optDouble)) : this.zzcox.zza(string, new zzaac(this, z, optDouble, optBoolean, string));
        }
        zzd(0, z);
        return zzali.zzh(null);
    }

    static zzaof zzb(zzalt<zzaof> zzalt) {
        try {
            return (zzaof) zzalt.get((long) ((Integer) zzlc.zzio().zzd(zzoi.zzbsq)).intValue(), TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            zzahw.zzc("InterruptedException occurred while waiting for video to load", e);
            Thread.currentThread().interrupt();
            return null;
        } catch (CancellationException | ExecutionException | TimeoutException e2) {
            zzahw.zzc("Exception occurred while waiting for video to load", e2);
            return null;
        }
    }

    private static Integer zzb(JSONObject jSONObject, String str) {
        try {
            JSONObject jSONObject2 = jSONObject.getJSONObject(str);
            return Integer.valueOf(Color.rgb(jSONObject2.getInt("r"), jSONObject2.getInt("g"), jSONObject2.getInt("b")));
        } catch (JSONException unused) {
            return null;
        }
    }

    /* JADX INFO: finally extract failed */
    private final zzahd zzc(zzpx zzpx) {
        int i;
        synchronized (this.mLock) {
            try {
                int i2 = this.mErrorCode;
                if (zzpx == null && this.mErrorCode == -2) {
                    i2 = 0;
                }
                i = i2;
            } catch (Throwable th) {
                while (true) {
                    throw th;
                }
            }
        }
        zzpx zzpx2 = i != -2 ? null : zzpx;
        zzkk zzkk = this.zzcob.zzcvm.zzcrv;
        List<String> list = this.zzcob.zzdcw.zzchw;
        List<String> list2 = this.zzcob.zzdcw.zzchx;
        List<String> list3 = this.zzcpa;
        int i3 = this.zzcob.zzdcw.orientation;
        long j = this.zzcob.zzdcw.zzcic;
        String str = this.zzcob.zzcvm.zzcry;
        zzko zzko = this.zzcob.zzaud;
        long j2 = this.zzcob.zzdcw.zzctn;
        List<String> list4 = list;
        long j3 = this.zzcob.zzdcn;
        return new zzahd(zzkk, (zzaof) null, list4, i, list2, list3, i3, j, str, false, (zzvp) null, (zzwi) null, (String) null, (zzvq) null, (zzvs) null, 0, zzko, j2, j3, this.zzcob.zzdco, this.zzcob.zzdcw.zzctt, this.zzcpb, zzpx2, (zzagd) null, (List<String>) null, (List<String>) null, this.zzcob.zzdcw.zzcuf, this.zzcob.zzdcw.zzcug, (String) null, this.zzcob.zzdcw.zzchz, this.zzcpc, this.zzcob.zzdcu, this.zzcob.zzdcw.zzaqw, this.zzcob.zzdcv);
    }

    /* access modifiers changed from: private */
    public final void zzc(zzro zzro, String str) {
        try {
            zzry zzs = this.zzcoy.zzs(zzro.getCustomTemplateId());
            if (zzs != null) {
                zzs.zzb(zzro, str);
            }
        } catch (RemoteException e) {
            StringBuilder sb = new StringBuilder(40 + String.valueOf(str).length());
            sb.append("Failed to call onCustomClick for asset ");
            sb.append(str);
            sb.append(".");
            zzahw.zzc(sb.toString(), e);
        }
    }

    private static String[] zzd(JSONObject jSONObject, String str) throws JSONException {
        JSONArray optJSONArray = jSONObject.optJSONArray(str);
        if (optJSONArray == null) {
            return null;
        }
        String[] strArr = new String[optJSONArray.length()];
        for (int i = 0; i < optJSONArray.length(); i++) {
            strArr[i] = optJSONArray.getString(i);
        }
        return strArr;
    }

    private static <V> zzalt<List<V>> zzl(List<zzalt<V>> list) {
        zzamd zzamd = new zzamd();
        int size = list.size();
        AtomicInteger atomicInteger = new AtomicInteger(0);
        for (zzalt<V> zza : list) {
            zza.zza(new zzaad(atomicInteger, size, zzamd, list), zzaid.zzdfi);
        }
        return zzamd;
    }

    /* access modifiers changed from: private */
    public static <V> List<V> zzm(List<zzalt<V>> list) throws ExecutionException, InterruptedException {
        ArrayList arrayList = new ArrayList();
        for (zzalt<V> zzalt : list) {
            Object obj = zzalt.get();
            if (obj != null) {
                arrayList.add(obj);
            }
        }
        return arrayList;
    }

    /* access modifiers changed from: private */
    /* JADX WARNING: Code restructure failed: missing block: B:12:0x0048, code lost:
        if (r3.length() != 0) goto L_0x004e;
     */
    /* JADX WARNING: Removed duplicated region for block: B:20:0x007f A[Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }] */
    /* JADX WARNING: Removed duplicated region for block: B:52:0x012d A[Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }] */
    /* JADX WARNING: Removed duplicated region for block: B:53:0x012e A[Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }] */
    /* JADX WARNING: Removed duplicated region for block: B:61:0x0176 A[Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }] */
    /* JADX WARNING: Removed duplicated region for block: B:74:0x01a3  */
    /* renamed from: zznv */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final com.google.android.gms.internal.zzahd call() {
        /*
            r13 = this;
            r0 = 0
            r1 = 0
            com.google.android.gms.ads.internal.zzbb r2 = r13.zzcoy     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.String r11 = r2.getUuid()     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            boolean r2 = r13.zznw()     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r2 != 0) goto L_0x0078
            com.google.android.gms.internal.zzamd r2 = new com.google.android.gms.internal.zzamd     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r2.<init>()     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzzx r2 = new com.google.android.gms.internal.zzzx     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r2.<init>()     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            org.json.JSONObject r2 = new org.json.JSONObject     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzahe r3 = r13.zzcob     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzacj r3 = r3.zzdcw     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.String r3 = r3.body     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r2.<init>(r3)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            org.json.JSONObject r3 = new org.json.JSONObject     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzahe r4 = r13.zzcob     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzacj r4 = r4.zzdcw     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.String r4 = r4.body     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r3.<init>(r4)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            int r4 = r3.length()     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r4 == 0) goto L_0x004a
            java.lang.String r4 = "ads"
            org.json.JSONArray r3 = r3.optJSONArray(r4)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r3 == 0) goto L_0x0041
            org.json.JSONObject r3 = r3.optJSONObject(r1)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            goto L_0x0042
        L_0x0041:
            r3 = r0
        L_0x0042:
            if (r3 == 0) goto L_0x004a
            int r3 = r3.length()     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r3 != 0) goto L_0x004e
        L_0x004a:
            r3 = 3
            r13.zzz(r3)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
        L_0x004e:
            com.google.android.gms.internal.zzaan r3 = r13.zzarm     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzalt r2 = r3.zzh(r2)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            long r3 = zzcow     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.util.concurrent.TimeUnit r5 = java.util.concurrent.TimeUnit.SECONDS     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.Object r2 = r2.get(r3, r5)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            org.json.JSONObject r2 = (org.json.JSONObject) r2     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.String r3 = "success"
            boolean r3 = r2.optBoolean(r3, r1)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r3 == 0) goto L_0x0078
            java.lang.String r3 = "json"
            org.json.JSONObject r2 = r2.getJSONObject(r3)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.String r3 = "ads"
            org.json.JSONArray r2 = r2.optJSONArray(r3)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            org.json.JSONObject r2 = r2.getJSONObject(r1)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r8 = r2
            goto L_0x0079
        L_0x0078:
            r8 = r0
        L_0x0079:
            boolean r2 = r13.zznw()     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r2 != 0) goto L_0x0122
            if (r8 != 0) goto L_0x0083
            goto L_0x0122
        L_0x0083:
            java.lang.String r2 = "template_id"
            java.lang.String r2 = r8.getString(r2)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzahe r3 = r13.zzcob     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzacf r3 = r3.zzcvm     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzqh r3 = r3.zzauq     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r3 == 0) goto L_0x009a
            com.google.android.gms.internal.zzahe r3 = r13.zzcob     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzacf r3 = r3.zzcvm     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzqh r3 = r3.zzauq     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            boolean r3 = r3.zzbzj     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            goto L_0x009b
        L_0x009a:
            r3 = r1
        L_0x009b:
            com.google.android.gms.internal.zzahe r4 = r13.zzcob     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzacf r4 = r4.zzcvm     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzqh r4 = r4.zzauq     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r4 == 0) goto L_0x00ac
            com.google.android.gms.internal.zzahe r4 = r13.zzcob     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzacf r4 = r4.zzcvm     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzqh r4 = r4.zzauq     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            boolean r4 = r4.zzbzl     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            goto L_0x00ad
        L_0x00ac:
            r4 = r1
        L_0x00ad:
            java.lang.String r5 = "2"
            boolean r5 = r5.equals(r2)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r5 == 0) goto L_0x00bf
            com.google.android.gms.internal.zzaao r2 = new com.google.android.gms.internal.zzaao     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzahe r5 = r13.zzcob     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            boolean r5 = r5.zzdcv     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r2.<init>(r3, r4, r5)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            goto L_0x0123
        L_0x00bf:
            java.lang.String r5 = "1"
            boolean r5 = r5.equals(r2)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r5 == 0) goto L_0x00d1
            com.google.android.gms.internal.zzaap r2 = new com.google.android.gms.internal.zzaap     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzahe r5 = r13.zzcob     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            boolean r5 = r5.zzdcv     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r2.<init>(r3, r4, r5)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            goto L_0x0123
        L_0x00d1:
            java.lang.String r4 = "3"
            boolean r2 = r4.equals(r2)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r2 == 0) goto L_0x011f
            java.lang.String r2 = "custom_template_id"
            java.lang.String r2 = r8.getString(r2)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzamd r4 = new com.google.android.gms.internal.zzamd     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r4.<init>()     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            android.os.Handler r5 = com.google.android.gms.internal.zzaij.zzdfn     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzzz r6 = new com.google.android.gms.internal.zzzz     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r6.<init>(r13, r4, r2)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r5.post(r6)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            long r5 = zzcow     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.util.concurrent.TimeUnit r2 = java.util.concurrent.TimeUnit.SECONDS     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.Object r2 = r4.get(r5, r2)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r2 == 0) goto L_0x00fe
            com.google.android.gms.internal.zzaaq r2 = new com.google.android.gms.internal.zzaaq     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r2.<init>(r3)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            goto L_0x0123
        L_0x00fe:
            java.lang.String r2 = "No handler for custom template: "
            java.lang.String r3 = "custom_template_id"
            java.lang.String r3 = r8.getString(r3)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.String r3 = java.lang.String.valueOf(r3)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            int r4 = r3.length()     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r4 == 0) goto L_0x0115
            java.lang.String r2 = r2.concat(r3)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            goto L_0x011b
        L_0x0115:
            java.lang.String r3 = new java.lang.String     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r3.<init>(r2)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r2 = r3
        L_0x011b:
            com.google.android.gms.internal.zzahw.e(r2)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            goto L_0x0122
        L_0x011f:
            r13.zzz(r1)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
        L_0x0122:
            r2 = r0
        L_0x0123:
            boolean r3 = r13.zznw()     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r3 != 0) goto L_0x0171
            if (r2 == 0) goto L_0x0171
            if (r8 != 0) goto L_0x012e
            goto L_0x0171
        L_0x012e:
            java.lang.String r3 = "tracking_urls_and_actions"
            org.json.JSONObject r3 = r8.getJSONObject(r3)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.String r4 = "impression_tracking_urls"
            java.lang.String[] r4 = zzd((org.json.JSONObject) r3, (java.lang.String) r4)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r4 != 0) goto L_0x013e
            r4 = r0
            goto L_0x0142
        L_0x013e:
            java.util.List r4 = java.util.Arrays.asList(r4)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
        L_0x0142:
            r13.zzcpa = r4     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.String r4 = "active_view"
            org.json.JSONObject r3 = r3.optJSONObject(r4)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r13.zzcpb = r3     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.String r3 = "debug_signals"
            java.lang.String r3 = r8.optString(r3)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r13.zzcpc = r3     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzpx r2 = r2.zza(r13, r8)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzpz r12 = new com.google.android.gms.internal.zzpz     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            android.content.Context r4 = r13.mContext     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.ads.internal.zzbb r5 = r13.zzcoy     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzaan r6 = r13.zzarm     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzcv r7 = r13.zzbyz     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzahe r3 = r13.zzcob     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzacf r3 = r3.zzcvm     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzala r10 = r3.zzatz     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r3 = r12
            r9 = r2
            r3.<init>(r4, r5, r6, r7, r8, r9, r10, r11)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r2.zzb(r12)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            goto L_0x0172
        L_0x0171:
            r2 = r0
        L_0x0172:
            boolean r3 = r2 instanceof com.google.android.gms.internal.zzpo     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            if (r3 == 0) goto L_0x018c
            r3 = r2
            com.google.android.gms.internal.zzpo r3 = (com.google.android.gms.internal.zzpo) r3     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzzx r4 = new com.google.android.gms.internal.zzzx     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r4.<init>()     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzaaa r5 = new com.google.android.gms.internal.zzaaa     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r5.<init>(r13, r3)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            r4.zzcov = r5     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            com.google.android.gms.internal.zzaan r3 = r13.zzarm     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            java.lang.String r4 = "/nativeAdCustomClick"
            r3.zza((java.lang.String) r4, r5)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
        L_0x018c:
            com.google.android.gms.internal.zzahd r2 = r13.zzc(r2)     // Catch:{ InterruptedException | CancellationException | ExecutionException -> 0x019f, JSONException -> 0x0199, TimeoutException -> 0x0195, Exception -> 0x0191 }
            return r2
        L_0x0191:
            r2 = move-exception
            java.lang.String r3 = "Error occured while doing native ads initialization."
            goto L_0x019c
        L_0x0195:
            r2 = move-exception
            java.lang.String r3 = "Timeout when loading native ad."
            goto L_0x019c
        L_0x0199:
            r2 = move-exception
            java.lang.String r3 = "Malformed native JSON response."
        L_0x019c:
            com.google.android.gms.internal.zzahw.zzc(r3, r2)
        L_0x019f:
            boolean r2 = r13.zzcoz
            if (r2 != 0) goto L_0x01a6
            r13.zzz(r1)
        L_0x01a6:
            com.google.android.gms.internal.zzahd r0 = r13.zzc(r0)
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.gms.internal.zzzy.call():com.google.android.gms.internal.zzahd");
    }

    private final boolean zznw() {
        boolean z;
        synchronized (this.mLock) {
            z = this.zzcoz;
        }
        return z;
    }

    private final void zzz(int i) {
        synchronized (this.mLock) {
            this.zzcoz = true;
            this.mErrorCode = i;
        }
    }

    public final zzalt<zzpj> zza(JSONObject jSONObject, String str, boolean z, boolean z2) throws JSONException {
        JSONObject jSONObject2 = z ? jSONObject.getJSONObject(str) : jSONObject.optJSONObject(str);
        if (jSONObject2 == null) {
            jSONObject2 = new JSONObject();
        }
        return zza(jSONObject2, z, z2);
    }

    public final List<zzalt<zzpj>> zza(JSONObject jSONObject, String str, boolean z, boolean z2, boolean z3) throws JSONException {
        JSONArray optJSONArray = jSONObject.optJSONArray(str);
        ArrayList arrayList = new ArrayList();
        if (optJSONArray == null || optJSONArray.length() == 0) {
            zzd(0, false);
            return arrayList;
        }
        int length = z3 ? optJSONArray.length() : 1;
        for (int i = 0; i < length; i++) {
            JSONObject jSONObject2 = optJSONArray.getJSONObject(i);
            if (jSONObject2 == null) {
                jSONObject2 = new JSONObject();
            }
            arrayList.add(zza(jSONObject2, false, z2));
        }
        return arrayList;
    }

    public final Future<zzpj> zza(JSONObject jSONObject, String str, boolean z) throws JSONException {
        JSONObject jSONObject2 = jSONObject.getJSONObject(str);
        boolean optBoolean = jSONObject2.optBoolean("require", true);
        if (jSONObject2 == null) {
            jSONObject2 = new JSONObject();
        }
        return zza(jSONObject2, optBoolean, z);
    }

    public final zzalt<zzaof> zzc(JSONObject jSONObject, String str) throws JSONException {
        JSONObject optJSONObject = jSONObject.optJSONObject(str);
        if (optJSONObject == null) {
            return zzali.zzh(null);
        }
        if (TextUtils.isEmpty(optJSONObject.optString("vast_xml"))) {
            zzahw.zzcz("Required field 'vast_xml' is missing");
            return zzali.zzh(null);
        }
        zzaaf zzaaf = new zzaaf(this.mContext, this.zzbyz, this.zzcob, this.zzanh, this.zzcoy);
        zzamd zzamd = new zzamd();
        zzaly.zzdjt.execute(new zzaag(zzaaf, optJSONObject, zzamd));
        return zzamd;
    }

    public final void zzd(int i, boolean z) {
        if (z) {
            zzz(i);
        }
    }

    public final zzalt<zzph> zzg(JSONObject jSONObject) throws JSONException {
        JSONObject optJSONObject = jSONObject.optJSONObject("attribution");
        if (optJSONObject == null) {
            return zzali.zzh(null);
        }
        String optString = optJSONObject.optString(MimeTypes.BASE_TYPE_TEXT);
        int optInt = optJSONObject.optInt("text_size", -1);
        Integer zzb = zzb(optJSONObject, "text_color");
        Integer zzb2 = zzb(optJSONObject, "bg_color");
        int optInt2 = optJSONObject.optInt("animation_ms", 1000);
        int optInt3 = optJSONObject.optInt("presentation_ms", 4000);
        int i = (this.zzcob.zzcvm.zzauq == null || this.zzcob.zzcvm.zzauq.versionCode < 2) ? 1 : this.zzcob.zzcvm.zzauq.zzbzm;
        boolean optBoolean = optJSONObject.optBoolean("allow_pub_rendering");
        List arrayList = new ArrayList();
        if (optJSONObject.optJSONArray("images") != null) {
            arrayList = zza(optJSONObject, "images", false, false, true);
        } else {
            arrayList.add(zza(optJSONObject, "image", false, false));
        }
        return zzali.zza(zzl(arrayList), new zzaab(this, optString, zzb2, zzb, optInt, optInt3, optInt2, i, optBoolean), (Executor) zzaid.zzdfi);
    }
}
